<?php
namespace app\enterprise\controller;
use think\Controller;
use think\Cookie;
use think\Request;

/**
 * Created by PhpStorm.
 * User: zd
 * Date: 2018/11/20
 * Time: 15:03
 */
class BaseController extends Controller
{
    public $appid = '';
    public $token = '';
    //初始化
    protected function _initialize(){
        if(!strpos($_SERVER["HTTP_USER_AGENT"],"MicroMessenger")){
            $this->error('请用微信浏览此应用');
        }
        $url  =  $this->request->url(true);
        $appid = Request::instance()->param('corpid');//接收传值
        $token = Cookie::get('Token');
        if (!empty($token)){
            $config =  $this->getWxConfig($url,$token,$appid);
            $this->assign('config',$config);
        }else{
            $this->token = $token;
        }
    }

    /**
     * 获取js-sdk配置信息
     * @param $baseUrl
     * @param $token
     * @param $corpid
     * @return mixed
     */
    public function getWxConfig($baseUrl,$token,$corpid){
        $url = 'https://minitest.17jxyx.com/api/v1/ai/config';
        $params = ['corpid'=>$corpid,'url'=>$baseUrl];
        $result = curl_post($url,$token,$params);
        return $result;
    }

}